#ifndef __spi_ms41929_h__
#define __spi_ms41929_h__

/*
SPI0 基地址是 0x120C_0000
SPI1 基地址是 0x120C_1000
SPI2 基地址是 0x120C_2000
*/
#define SSP_BASE (0x120c1000)

/*
SPI1 pinmux
*/
#define SPI1_SCLK (0x112F0020)
#define SPI1_SDO (0x112F0024)
#define SPI1_CSN0 (0x112f0028)
#define SPI1_SDI (0x112F002C)
#define SPI1_CSN1 (0x112f0030)
/*
PERI_CRG111 - SPI Clock Control
*/
#define PERI_CRG111 (0x120101BC)

/*
MISC_CTRL0  - SP1_CSN0 Check
spi1_cs0_pctrl -- spi1 csn0 select
     0:SPI1_CSN0  low enable
     1:SPI1_CSN0  high enable

ssp1_cs_sel -- SPI1 cs select
    0:SPI1_CSN0
    1:SPI1_CSN1
*/
#define MISC_CTRL0 (0x12030000 + 0x0000)

#define SSP_SIZE 0x1000 // 4KB
#define DEFAULT_MD_LEN (128)
#define IO_ADDRESS_VERIFY(x) (x)

/* SSP register definition .*/
#define SSP_CR0 IO_ADDRESS_VERIFY(SSP_BASE + 0x00)
#define SSP_CR1 IO_ADDRESS_VERIFY(SSP_BASE + 0x04)
#define SSP_DR IO_ADDRESS_VERIFY(SSP_BASE + 0x08)
#define SSP_SR IO_ADDRESS_VERIFY(SSP_BASE + 0x0C)
#define SSP_CPSR IO_ADDRESS_VERIFY(SSP_BASE + 0x10)
#define SSP_IMSC IO_ADDRESS_VERIFY(SSP_BASE + 0x14)
#define SSP_RIS IO_ADDRESS_VERIFY(SSP_BASE + 0x18)
#define SSP_MIS IO_ADDRESS_VERIFY(SSP_BASE + 0x1C)
#define SSP_ICR IO_ADDRESS_VERIFY(SSP_BASE + 0x20)
#define SSP_DMACR IO_ADDRESS_VERIFY(SSP_BASE + 0x24)
#define SSP_SPITXFIFOCR IO_ADDRESS_VERIFY(SSP_BASE + 0x28)
#define SSP_SPIRXFIFOCR IO_ADDRESS_VERIFY(SSP_BASE + 0x2C)

#define SPI_SR_BSY (0x1 << 4) /* spi busy flag */
#define SPI_SR_TFE (0x1 << 0) /* Whether to send fifo is empty */
#define SPI_SR_RNE (0x1 << 2) /* Whether to receive fifo is empty ,0:empty,1:not empty*/
#define SPI_DATA_WIDTH_8 (8)
#define SPI_DATA_WIDTH_16 (16)
#define SPI_SPO (1) /* 极性 */
#define SPI_SPH (1) /* 相性 */
#define SPI_SCR (7) //(8)
#define SPI_CPSDVSR (4)
#define SPI_FRAMEMODE_MOTOR (0)
#define SPI_FRAMEMODE_NATION (2)
#define SPI_BITEND_LSB_MSB (1)

#define MAX_WAIT 10000

// JTAG  -> SPI1
#define JTAG_TCK_IO_REG (0x112F0024)
#define JTAG_TCK_IO_SPI1_SD0 (0x0601)

#define JTAG_TRSTN_IO_REG (0x112F0020)
#define JTAG_TRSTN_IO_SPI1_SCLK (0x0601)

#define JTAG_TD0_IO_REG (0x112F002C)
#define JTAG_TD0_IO_SPI1_SDI (0x0401)

#define JTAG_TMS_IO_REG (0x112F0028)
#define JTAG_TMS_IO_GPIO8_2 (0x0504)

#define PWM0_PIN6_6_IO_CONF (0x111F0024)
#define PERI_CRG111  (0x120101BC)
#define PWM0_CFG0    (0x12070000)
#define PWM0_CFG1    (0x12070004)
#define PWM0_CFG2    (0x12070008)
#define PWM0_CTRL    (0x1207000C)
#define PWM0_STATE0  (0x12070010)
#define PWM0_STATE1  (0x12070014)
#define PWM0_STATE2  (0x12070018)

unsigned int spi_ms41929_write(unsigned char addr, unsigned short data);
// void spi_ms41929_read_init();
// void spi_ms41929_write_init();
unsigned short spi_ms41929_read(unsigned char addr);
void spi_ms41929_init();
void spi_ms41929_write_set_framemode();
void spi_ms41929_VDFZ_pulse();

//#include "zoom_lens.h"

// typedef struct {
//   int ch_num;   // lens number;
//   char sns[32]; // sensor name;
//   char lens[32];// lens name;
// }gsf_lens_ini_t;

// int (*gsf_lens_init)(gsf_lens_ini_t *ini);
// int (*gsf_lens_start)(int ch, char *ttyAMA);
// int (*gsf_lens_ircut)(int ch, int dayNight);
//int gsf_lens_zoom(int ch, int dir, int speed);
//int gsf_lens_focus(int ch, int dir, int speed);
//int gsf_lens_stop(int ch);
int zoom_lens_init();
// int (*gsf_lens_zoom)(int ch,  int dir, int speed);
// int (*gsf_lens_focus)(int ch, int dir, int speed);
// int (*gsf_lens_stop)(int ch) ;
// int (*gsf_lens_cal)(int ch);

#endif